package com.example.mountainwalker.controller;

import com.example.mountainwalker.entity.StrategyFavoriteInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sft")
public class StrategyFavoriteController {

    @Autowired
    private com.example.mountainwalker.service.StrategyFavoriteService strategyFavoriteService;

    //http://localhost:8080/sft/list
    @GetMapping("/list")
    public List<StrategyFavoriteInfo> getStrategyFavoriteList() {
        List<StrategyFavoriteInfo> strategyFavoriteInfo = strategyFavoriteService.getStrategyFavoriteInfo();
        return strategyFavoriteInfo;
    }

    // http://localhost:8080/sft/find/1
    @GetMapping("/find/{StrategyFavoriteID}")
    public StrategyFavoriteInfo getStrategyFavoriteById(@PathVariable Integer StrategyFavoriteID){
        StrategyFavoriteInfo strategyFavoriteInfo = strategyFavoriteService.getStrategyFavoriteInfoById(StrategyFavoriteID);
        return strategyFavoriteInfo;
    }

    // http://localhost:8080/sft/delete/1
    @DeleteMapping("/delete/{StrategyFavoriteID}")
    public int deleteStrategyFavoriteById(@PathVariable("StrategyFavoriteID") Integer StrategyFavoriteID) {
        int result = strategyFavoriteService.deleteStrategyFavoriteInfoById(StrategyFavoriteID);
        System.out.println("删除结果：" + result);  // 添加日志
        return result;
    }

    // http://localhost:8080/sft/insert
    @PostMapping("/insert")
    public int insertStrategyFavoriteInfo(@RequestBody StrategyFavoriteInfo strategyFavoriteInfo) {
        System.out.println("接受到的数据:"+strategyFavoriteInfo);
        int result = strategyFavoriteService.insertStrategyFavoriteInfo(strategyFavoriteInfo);
        return result;
    }

    //http://localhost:8080/sft/update
    @PutMapping("/update")
    public int updateStrategyFavoriteInfo(@RequestBody StrategyFavoriteInfo strategyFavoriteInfo){
        int result= strategyFavoriteService.updateStrategyFavoriteInfo(strategyFavoriteInfo);
        return result;
    }




}
